//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <stdio.h>
#include "Scalar.h"
#include "send/send.h"
#include <DevicePower.h>

void Scale(unsigned long mode);
void Scale_Initialize();
float Scale_GetCpuVoltage();
unsigned Scale_GetCpuFrequency();

Scalar scalar;
extern int IsPowerManagerNeeded;
Scalar::Scalar()
{
}

Scalar::~Scalar()
{
    printf("emulator quit\n");
    if(IsPowerManagerNeeded)Power_UpdateDevicePower(0, (unsigned long)-1);
}

void Scalar::ChangeMode(unsigned long NewMode)
{
    if (NewMode != pre_mode) {
        pre_mode=NewMode;
        Scale(NewMode);
        //Send(Scale_GetCpuFrequency(),Scale_GetCpuVoltage());//notify the displayer to display.
        Power_UpdateDevicePower(0,NewMode);
    }
}

int Scalar_Initialize()
{
    Send_Initialize();
    Scale_Initialize();
    return 0;
}

void Scalar_ChangeCpuMode(unsigned long NewMode)
{
    scalar.ChangeMode(NewMode);
}

unsigned long Scalar_GetCpuMode()
{
    return scalar.pre_mode;
}

void Scalar_SendDevicePower(void * pBuffer, int index)//to send device power information to display.
{
    SendEx(pBuffer,index);
}

unsigned long Scalar_GetCpuPower(unsigned long Mode)
{
    return (unsigned long)(Scale_GetCpuFrequency()*Scale_GetCpuVoltage()*Scale_GetCpuVoltage());
}
